package com.yhc.my.an_meishia.adapters;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yhc.my.an_meishia.R;
import com.yhc.my.an_meishia.bean.HotShows;

import java.util.List;

/**
 * Created by Administrator on 2016/9/20 0020.
 */
public class HotAdapter extends BaseAdapter {
private List<HotShows> mList;
    private Context mContext;
    private ViewHolder holder;

    public HotAdapter(FragmentActivity activity,Context context, List<HotShows> list) {
        this.mList=list;
        this.mContext = context;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return mList!=null?mList.size():0;
    }

    @Override
    public Object getItem(int position) {
        return mList!=null?mList.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.hot_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
           holder = (ViewHolder) convertView.getTag();
        }
        //绑定数据
        HotShows contents = mList.get(position);
        holder.tvTitle.setText(contents.getRecommend_caption());
        if (contents.getMedia()!=null){
            String likes_count = contents.getMedia().getLikes_count();
           holder.tvCount.setText(contents.getMedia().getLikes_count());
       }

        //下载图片
        String logo = contents.getRecommend_cover_pic();
        Glide.with(mContext).load(logo).placeholder(R.mipmap.ic_launcher).into(holder.ivLogo);
        return convertView;
    }
    class ViewHolder{
        TextView tvTitle,tvCount;
        ImageView ivLogo;
        public ViewHolder(View convertView){
            tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
            tvCount = (TextView) convertView.findViewById(R.id.tv_count);
            ivLogo = (ImageView) convertView.findViewById(R.id.iv_logo);
        }
    }
}
